﻿using System;
using System.Web;
using System.Data;
using System.Configuration;
using Ultimus.WFServer;
using Ultimus.OC;
using SureSoft.ServicesCore;
using SureSoft.IServicesCore;
using Entities;
using NBear.Common;
using NBear.Data;

namespace ProPublic
{
    public class ProPublic
    {
        private SureSoft.ServicesCore.ServicesLib oServicesLib = null;
        private string sDoMain = null;
        public ProPublic()
        {
            sDoMain = ConfigurationManager.AppSettings["DoMain"].ToString() + "/";
            oServicesLib = new ServicesLib();
        }

        #region 加密字符串
        /// <summary>
        /// 加密字符串；
        /// </summary>
        /// <param name="sEncryptString">待加密字符串</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：如果nReturn为0，此值为加密后的字符串；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase EncryptString(string sEncryptString)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.EncryptString(sEncryptString, out  oResultBase.sReturnValue, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 解密字符串
        /// <summary>
        /// 解密字符串
        /// </summary>
        /// <param name="sDecryptString">待解密字符串</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：如果nReturn为0，此值为加密后的字符串；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase DecryptString(string sDecryptString)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.DecryptString(sDecryptString, out  oResultBase.sReturnValue, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 通过TaskID获取Url
        /// <summary>
        /// 根据TaskID获取表单URL地址；
        /// </summary>
        /// <param name="sTaskId">任务编号</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：如果nReturn为0，此值为表单URL地址；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase GetFormUrl(string sTaskId)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.GetFormUrl(sTaskId, out  oResultBase.sReturnValue, out  oResultBase.sError))
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 通过TaskID获取TaskStruct对象
        /// <summary>
        /// 根据TaskID获取TaskStruct对象
        /// </summary>
        /// <param name="sTaskID">任务编号</param>
        /// <returns>返回ResultTaskStuct对象
        /// nReturn：0（成功），1（失败）；
        /// TaskStruct：如果nReturn为0，此值为表单信息；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultTaskStuct GetTaskStruct(string sTaskId)
        {
            ResultTaskStuct oResultTaskStuct = new ResultTaskStuct();
            try
            {
                if (oServicesLib.GetTaskStruct(sTaskId, out  oResultTaskStuct.oTaskStruct, out  oResultTaskStuct.sError) == false)
                {
                    oResultTaskStuct.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultTaskStuct.nReturn = 1;
                oResultTaskStuct.sError = ee.Message;
            }
            return oResultTaskStuct;
        }
        #endregion

        #region 通过流程名实例号获取流程走向图
        /// <summary>
        /// 通过流程名实例号获取流程走向图
        /// </summary>
        /// <param name="ProcessName">流程名称</param>
        /// <param name="IncidentNum">实例号</param>
        /// <param name="GraphStatus">返回的图形数组</param>
        /// <param name="ErrorInfo">错误信息</param>
        /// <returns>返回是否成功（true、false）</returns>
        /// UltWebClient/GraphicalView.aspx

        private bool GetProcessGrap(string ProcessName, int IncidentNum, ref byte[] GraphStatus, out string ErrorInfo)  //++++++++++
        {
            return oServicesLib.GetProcessGrap(ProcessName, IncidentNum, ref  GraphStatus, out  ErrorInfo);
        }
        #endregion

        #region 指派任务
        /// <summary>
        /// 指派任务
        /// </summary>
        /// <param name="sTaskID">任务编号</param>
        /// <param name="sToUserCode">任务指派用户编码</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase AssignTask(string sTaskId, string sToUserCode)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.AssignTask(sTaskId, sDoMain + sToUserCode, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }

            return oResultBase;
        }
        #endregion

        #region 获取已指派任务列表
        /// <summary>
        /// 获取已指派任务列表
        /// </summary>
        /// <param name="sUserCode">用户编码</param>
        /// <returns>返回ResultTaskStuct对象
        /// nReturn：0（成功），1（失败）；
        /// TaskStruct：如果nReturn为0，此值收回指派任务的列表；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultTaskStuctList AssignTaskList(string sUserCode)
        {
            ResultTaskStuctList oResultTaskStuctList = new ResultTaskStuctList();
            try
            {
                if (oServicesLib.AssignTaskList(sDoMain + sUserCode, out  oResultTaskStuctList.oTaskListStruct, out  oResultTaskStuctList.sError) == false)
                {
                    oResultTaskStuctList.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultTaskStuctList.nReturn = 1;
                oResultTaskStuctList.sError = ee.Message;
            }

            return oResultTaskStuctList;
        }
        #endregion

        #region 收回指派任务
        /// <summary>
        /// 收回指派任务
        /// </summary>
        /// <param name="sTaskId">任务TaskID</param>
        /// <param name="sUserCode">任务收回人</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase TakeBackTask(string sTaskId, string sUserCode)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.TakeBackTask(sTaskId, sDoMain + sUserCode, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }

            return oResultBase;
        }
        #endregion

        #region 指派用户所有当前任务
        /// <summary>
        /// 指派用户所有当前任务
        /// </summary>
        /// <param name="sFromUserCode">从谁</param>
        /// <param name="sToUserCode">到谁</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase AssignAllCurrentTasks(string sFromUserCode, string sToUserCode)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.AssignAllCurrentTasks(sDoMain + sFromUserCode, sDoMain + sToUserCode, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }

            return oResultBase;
        }
        #endregion

        #region 指派用户将来任务
        /// <summary>
        /// 指派用户将来任务
        /// </summary>
        /// <param name="sFromUserCode">从谁</param>
        /// <param name="sToUserCode">到谁</param>
        /// <param name="dTimeLimit">指派期限</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase AssignAllFutureTasks(string sFromUserCode, string sToUserCode, DateTime dTimeLimit)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.AssignAllFutureTasks(sDoMain + sFromUserCode, sDoMain + sToUserCode, dTimeLimit, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }

            return oResultBase;
        }
        #endregion

        #region 取消实例
        /// <summary>
        /// 取消实例
        /// </summary>
        /// <param name="sProcessName">流程名称</param>
        /// <param name="sIncidentNum">实例号</param>
        /// <param name="sUserCode">用户编码</param>
        /// <param name="sReason">原因</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase AbortIncident(string sProcessName, int sIncidentNum, string sUserCode, string sReason)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.AbortIncident(sProcessName, sIncidentNum, sDoMain + sUserCode, sReason, out oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 取消任务
        /// <summary>
        /// 取消任务
        /// </summary>
        /// <param name="sTaskId">任务编号</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase AbortTask(string sTaskId)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.AbortTask(sTaskId, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 删除任务
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="sTaskId">任务编号</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase DeleteTask(string sTaskId)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.DeleteTask(sTaskId, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion


        #region 获取同事信息
        /// <summary>
        /// 获取同事信息
        /// </summary>
        /// <param name="sUserCode">用户编码</param>
        /// <returns>返回UserPrefStruct对象
        /// nReturn：0（成功），1（失败）；
        /// UserPrefStruct：如果nReturn为0，此值用户信息；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultUserPrefStructList GetUserPrefs(string sUserCode)
        {
            ResultUserPrefStructList oResultUserPrefStructList = new ResultUserPrefStructList();
            try
            {
                if (oServicesLib.GetUserPrefs(sDoMain + sUserCode, out oResultUserPrefStructList.oUserPrefStruct, out  oResultUserPrefStructList.sError) == false)
                {
                    oResultUserPrefStructList.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultUserPrefStructList.nReturn = 1;
                oResultUserPrefStructList.sError = ee.Message;
            }
            return oResultUserPrefStructList;
        }
        #endregion

        #region 设置同事信息
        /// <summary>
        /// 设置同事信息
        /// </summary>
        /// <param name="sUserCode">用户编码</param>
        /// <param name="oUserPrefTable">同事列表信息UserPrefStruct对象数组</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase SetUserPrefs(string sUserCode, UserPrefStruct[] oUserPref)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.SetUserPrefs(sDoMain + sUserCode, oUserPref, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 获取发起任务列表
        /// <summary>
        /// 获取指定用户起始任务
        /// </summary>
        /// <param name="sUserCode">指定用户名</param>
        /// <returns>返回TaskStuctList对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：如果nReturn为0，此值为获取的发起任务列表；；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultTaskStuctList GetInitTaskList(string sUserCode)
        {
            ResultTaskStuctList oResultTaskStuctList = new ResultTaskStuctList();
            try
            {
                if (oServicesLib.GetInitTaskList(sDoMain + sUserCode, ref  oResultTaskStuctList.oTaskListStruct, out  oResultTaskStuctList.sError) == false)
                {
                    oResultTaskStuctList.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultTaskStuctList.nReturn = 1;
                oResultTaskStuctList.sError = ee.Message;
            }
            return oResultTaskStuctList;
        }
        #endregion

        #region 获取不属于指定用户的发起任务列表
        /// <summary>
        /// 获取不属于指定用户的发起任务列表；
        /// </summary>
        /// <param name="sUserCode">指定用户名</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：如果nReturn为0，此值为获取的发起任务流程名称列表；；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase GetNotInitTaskList(string sUserCode)
        {
            ResultBase oResultBase = new ResultBase();
            Gateway oGateway = null;
            ResultTaskStuctList oResultTaskStuctList = null;
            string sTemp = string.Empty;
            DataRow[] oDataRow = null;
            try
            {
                oResultTaskStuctList = new ResultTaskStuctList();
                sTemp = "";
                bool bRetu = oServicesLib.GetInitTaskList(sDoMain + sUserCode, ref  oResultTaskStuctList.oTaskListStruct, out  oResultTaskStuctList.sError);
                if (bRetu == true)
                {
                    foreach (TaskListStruct oTaskListStruct in oResultTaskStuctList.oTaskListStruct)
                    {
                        if (oTaskListStruct == null) { continue; }
                        sTemp = sTemp + "'" + oTaskListStruct.ProcessName + "',";
                    }
                    sTemp = sTemp.TrimEnd(',');
                }
                oGateway = new Gateway("strSqlCon");
                DataTable oDataTable = oGateway.FromCustomSql(" select distinct processname from initiate ").ToDataSet().Tables[0];
                if (oDataTable != null && oDataTable.Rows.Count > 0)
                {
                    if (bRetu == true)
                    {
                        oDataRow = oDataTable.Select(" processname not in (" + sTemp + ")");
                        sTemp = "";
                        foreach (DataRow oDr in oDataRow)
                        {
                            sTemp = sTemp + "," + oDr["processname"].ToString().Trim();
                        }
                    }
                    else
                    {
                        sTemp = "";
                        foreach (DataRow _oDr in oDataTable.Rows)
                        {
                            sTemp = sTemp + "," + _oDr["processname"].ToString().Trim();
                        }
                    }
                    oResultBase.nReturn = 0;
                    oResultBase.sReturnValue = sTemp.TrimStart(',');
                }
                else
                {
                    oResultBase.nReturn = 0;
                    oResultBase.sReturnValue = string.Empty;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            finally
            {
                oGateway = null;
                oResultTaskStuctList = null;
                sTemp = null;
            }
            return oResultBase;
        }
        #endregion

        #region 获取发起任务模板列表
        /// <summary>
        /// 获取发起任务模板列表
        /// </summary>
        /// <param name="sUserCode">指定用户名</param>
        /// <returns>返回TaskStuctList对象
        /// nReturn：0（成功），1（失败）；
        /// UserPrefStruct：如果nReturn为0，此值为获取的发起任务模板列表；；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultTaskStuctList GetInitTaskTempList(string sUserCode)
        {
            ResultTaskStuctList oResultTaskStuctList = new ResultTaskStuctList();
            try
            {
                if (oServicesLib.GetInitTaskTempList(sDoMain + sUserCode, ref  oResultTaskStuctList.oTaskListStruct, out  oResultTaskStuctList.sError) == false)
                {
                    oResultTaskStuctList.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultTaskStuctList.nReturn = 1;
                oResultTaskStuctList.sError = ee.Message;
            }
            return oResultTaskStuctList;
        }
        #endregion

        #region 获取共享（队列）任务列表
        /// <summary>
        /// 获取共享（队列）任务列表
        /// </summary>
        /// <param name="sUserCode">用户编码</param>
        /// <returns>返回TaskStuctList对象
        /// nReturn：0（成功），1（失败）；
        /// UserPrefStruct：如果nReturn为0，此值为获取共享（队列）任务列表；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultTaskStuctList GetQueueTaskList(string sUserCode)
        {
            ResultTaskStuctList oResultTaskStuctList = new ResultTaskStuctList();
            try
            {
                if (oServicesLib.GetQueueTaskList(sDoMain + sUserCode, out  oResultTaskStuctList.oTaskListStruct, out  oResultTaskStuctList.sError) == false)
                {
                    oResultTaskStuctList.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultTaskStuctList.nReturn = 1;
                oResultTaskStuctList.sError = ee.Message;
            }
            return oResultTaskStuctList;
        }
        #endregion

        #region 获取共享任务
        /// <summary>
        /// 获取共享任务
        /// </summary>
        /// <param name="sTaskID">taskid</param>
        /// <param name="sUserName">指派给谁</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase GetQueueTasks(string sTaskId, string sUserName)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.GetQueueTasks(sTaskId, sDoMain + sUserName, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 获取高层主管
        /// <summary>
        /// 获取高层主管
        /// </summary>
        /// <param name="sUserName"></param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase GetSupervisor(string sUserName)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                oResultBase.sReturnValue = oServicesLib.GetSupervisor(sDoMain + sUserName);
                if (oResultBase.sReturnValue.Length == 0)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }

        /// <summary>
        /// 获取直属主管
        /// </summary>
        /// <param name="sUserName"></param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase GetManager(string sUserName)
        {

            ResultBase oResultBase = new ResultBase();
            try
            {
                oResultBase.sReturnValue = oServicesLib.GetManager(sDoMain + sUserName);
                if (oResultBase.sReturnValue.Length == 0)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 提交任务
        /// <summary>
        /// 提交任务
        /// </summary>
        /// <param name="sTaskId">任务编号</param>
        /// <param name="sSummary">标题</param>
        /// <param name="sMemo">备注</param>
        /// <param name="oVariables">变量数组</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：返回影响流程实例的实例号；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase Send(string sTaskId, string sUserCode, string sSummary, string[] LSID)
        {
            int nRetu = 0;
            ResultBase oResultBase = new ResultBase();

            #region 判断是否是重复提交 如果状态为已提交则返回
            Task oTask = new Task();
            oTask.InitializeFromTaskId(sTaskId);
            int oTaskStatus = oTask.nTaskStatus;
            if (oTaskStatus == 3)
            {
                oResultBase.nReturn = 1;
                return oResultBase;
            }
            #endregion

            try
            {
                if (oServicesLib.Send(sTaskId, sDoMain + sUserCode, sSummary, "", LSID, ref  nRetu, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
                else
                {
                    oResultBase.sReturnValue = Convert.ToString(nRetu);
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion
        #region 根据TaskID批量提交任务_梁晋添加
        /// <summary>
        /// 根据TaskID批量提交任务
        /// </summary>
        /// <param name="sTaskIds">任务编号</param>
        /// <param name="sUserCode">处理人账号</param>
        /// <param name="sSummary">业务标题</param>
        /// <param name="Spzt">审批状态：提交“0”、退回“2”</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：返回影响流程实例的实例号；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase SendByTaskID(string[] sTaskIds, string sUserCode, string sSummary, string Spzt)
        {
            int nRetu = 0;
            int taskNum = sTaskIds.Length;
            string[] LSID = new string[1];
            LSID[0] = Spzt;
            string userid = sDoMain + sUserCode;
            ResultBase oResultBase = new ResultBase();
            try
            {
                for (int i = 0; i < taskNum; i++)
                {
                    if (oServicesLib.PlSend(sTaskIds[i], userid, sSummary, "", LSID, ref  nRetu, out  oResultBase.sError) == false)
                    {
                        oResultBase.nReturn = 1;
                        return oResultBase;
                    }
                    else
                    {
                        oResultBase.sReturnValue = Convert.ToString(nRetu);
                    }
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion
        #region 发起流程
        /// <summary>
        /// 通过流程名称提交流程
        /// </summary>
        /// <param name="sProcessName">流程名称</param>
        /// <param name="sUserCode">用户账号</param>
        /// <param name="sSummary">摘要</param>
        /// <param name="sMemo"></param>
        /// <param name="oVariables"></param>
        /// <returns></returns>

        public ResultInt SendStartStepByProcessName(string sProcessName, string sUserCode, string sSummary, string[] LSID)
        {
            int nRetu = -1;
            ResultInt oResultInt = new ResultInt();
            try
            {
                ResultBase _oResultBase = this.GetInItTaskId(sUserCode, sProcessName);
                if (_oResultBase.nReturn == 0)
                {
                    if (oServicesLib.Send(_oResultBase.sReturnValue, sDoMain + sUserCode, sSummary, string.Empty, LSID, ref  nRetu, out  oResultInt.sError) == false)
                    {
                        oResultInt.nReturn = 1;
                    }
                    else
                    {
                        oResultInt.nReturn = 0;
                        oResultInt.nReturnValue = nRetu;
                    }
                }
                else
                {
                    oResultInt.nReturn = 1;
                    oResultInt.sError = _oResultBase.sError;
                }
            }
            catch (Exception ee)
            {
                oResultInt.nReturn = 1;
                oResultInt.sError = ee.Message;
            }
            return oResultInt;
        }
        #endregion
        #region 获取流程的发起TaskId
        /// <summary>
        /// 获取指定流程的发起任务TaskId；
        /// </summary>
        /// <param name="strUserName">用户</param>
        /// <param name="strProcess">流程名称</param>
        /// <param name="oTask">返回Task对象</param>
        /// <param name="strError"></param>
        /// <returns></returns>

        public ResultBase GetInItTaskId(string sUserCode, string strProcess)
        {
            Tasklist tasklist1 = null;
            TasklistFilter filter1 = null;
            Task oTask = null;
            ResultBase oResultBase = new ResultBase();
            try
            {
                sUserCode = sDoMain + sUserCode;
                tasklist1 = new Tasklist();
                filter1 = new TasklistFilter();
                oTask = new Task();
                filter1.strProcessNameFilter = strProcess;//流程名称；
                filter1.strArrUserName = new string[1] { sUserCode };//用户名;
                filter1.nFiltersMask = Filters.nFilter_Initiate;
                tasklist1.LoadFilteredTasks(filter1);//加载符合上述条件的流程信息;
                int nCount = tasklist1.GetTasksCount();//获取符合条件的流程数目;
                if (nCount > 0)
                {
                    oTask = tasklist1.GetFirstTask();
                    oResultBase.nReturn = 0;
                    oResultBase.sReturnValue = oTask.strTaskId;
                }
                else
                {
                    oResultBase.nReturn = 1;
                    oResultBase.sError = "没有查找到符合条件的流程信息!";
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            finally
            {
                tasklist1 = null;
                filter1 = null;
                oTask = null;
            }
            return oResultBase;
        }
        #endregion
        #region 退回任务
        /// <summary>
        /// 退回任务
        /// </summary>
        /// <param name="sTaskId">任务编号</param>
        /// <param name="sSummary">标题</param>
        /// <param name="sMemo">备注</param>
        /// <param name="oVariables">变量数组</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sError：如果nReturn 为1，此值为错误描述信息；
        /// </returns>

        public ResultBase Return(string sTaskId, string sUserCode, string sSummary, string sMemo, string[] oVariables)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.Return(sTaskId, sDoMain + sUserCode, sSummary, sMemo, oVariables, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
        #endregion

        #region 获取电子表格变量
        /// <summary>
        /// 获取电子表格变量
        /// </summary>
        /// <param name="TaskID">任务编号</param>
        /// <param name="VariableName">变量名</param>
        /// <returns>返回ResultBase对象
        /// nReturn：0（成功），1（失败）；
        /// sReturnValue：返回变量值；
        /// sError：如果nReturn 为1，此值为错误描述信息；

        public ResultBase GetVariableValue(string sTaskId, string sVariableName)
        {
            ResultBase oResultBase = new ResultBase();
            object obj = null;
            try
            {
                if (oServicesLib.GetVariableValue(sTaskId, sVariableName, out  obj, out  oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
                else
                {
                    oResultBase.sReturnValue = Convert.ToString(obj);
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            finally { obj = null; }
            return oResultBase;
        }
        #endregion

        /// <summary>
        /// 转发阅知
        /// </summary>
        /// <param name="sFromUserCode">来源账户</param>
        /// <param name="TaskId">转发阅知的TaskId列表；</param>
        /// <param name="sToUserCode">转到的用户</param>
        /// <param name="sText">转发意见</param>
        /// <returns></returns>

        public ResultBase ForWardReadKnow(string sFromUserCode, string TaskId, string sToUserCode, string sText)
        {
            ResultBase oResultBase = new ResultBase();
            try
            {
                if (oServicesLib.ForWardReadKnow(sFromUserCode, TaskId, sToUserCode, sText, out oResultBase.sError) == false)
                {
                    oResultBase.nReturn = 1;
                }
            }
            catch (Exception ee)
            {
                oResultBase.nReturn = 1;
                oResultBase.sError = ee.Message;
            }
            return oResultBase;
        }
    }
}